package son.nt.act4;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import son.nt.R;
import son.nt.util.LogUtil;
import android.app.Activity;
import android.content.Context;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class DateConvertActivity extends Activity{
	private static final String TAG = "DateConvertActivity";
	private EditText edit = null;
	private TextView txtConvert = null;
	private Context mContext = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act4_date_convert);
		mContext = this;
		edit = (EditText) findViewById(R.id.edtDate);
		txtConvert = (TextView) findViewById(R.id.txtDateConverted);
	}
	
	public void onClick(View v){
		switch (v.getId()) {
		case R.id.btnConvert:
			convert();
			break;

		default:
			break;
		}
	}
	
	public void convert(){
		try {
			String s = edit.getText().toString();
			//s = Mon, 15 Oct 2012 13:02:54 +0000

			Date date = new Date(s);
			String time = date.toString();
			int hour = date.getHours();
			txtConvert.setText(time);
			
			String path1 = "C://son.txt";
			String path2 = "/sdcard/son.txt";
			File f1 = new File(path1);
			File f2 = new File(path2);
			LogUtil.v(TAG, f2.getName());
			long l1 = f1.lastModified();
			f2.setLastModified(date.getTime());
			
//			 SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
//			    String newLastModified = "01/06/2012";
//			    Date newDate = sdf.parse(newLastModified);
//			    f2.setLastModified(newDate.getTime());
		} catch (Exception e) {
			LogUtil.e(mContext, TAG, "err convert:" + e.toString());
		}
	}
	
	

}
